package com.taikang.hmp.frame.common.web;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;

import com.taikang.hmp.frame.common.TKException;

/**
 * 没有注册的默认不用校验激活码
 * @author t-wangfugang
 *
 */
public class ActiveCodeRegistry {
	
	      
	    private static Map<String,Boolean> ACTIVE_CD_REGISTRY = new ConcurrentHashMap<String,Boolean>();
	
		private static ActiveCodeRegistry actviceCdRegistry = new ActiveCodeRegistry();
		
		
		
		private ActiveCodeRegistry(){
			if(ACTIVE_CD_REGISTRY == null){
				ACTIVE_CD_REGISTRY = new ConcurrentHashMap<String,Boolean>();
			}
			//校验功能是否需要校验后再使用,没有注册的 默认
			
			//------------------------泰康医生---------------------------------

			//注册
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.login.do.regist",Boolean.TRUE);
			//激活
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.userbase.do.updateActivation",Boolean.TRUE);
			//我的服务
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.userbase.do.getDate",Boolean.TRUE);
			//获取客户基本信息
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.userbase.do.getUserBaseInformation" ,Boolean.TRUE);
			//更新客户基本信息
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.userbase.do.updateUserBaseInformation" ,Boolean.TRUE);
			//客户更改密码
			ACTIVE_CD_REGISTRY.put("app.doctor.doctor.userbase.do.upatePassword",Boolean.TRUE);
			
		

		}
		
		public static ActiveCodeRegistry getInstance(){
			return actviceCdRegistry;
		}
		
		
		public Boolean containsMethod(String actionMethodKey){
			return ACTIVE_CD_REGISTRY.keySet().contains(actionMethodKey);
		}

		public Boolean isCheckAtvCd(String actionMethodKey){
			if(containsMethod(actionMethodKey)){
				return ACTIVE_CD_REGISTRY.get(actionMethodKey);
			}else{
				return Boolean.FALSE;
			}	
		}
		/**
		 * 获取URL
		 */
		public String getActionUrlKey(HttpServletRequest  request) {
			String pathinfo = request.getServletPath();
			if (StringUtils.startsWith(pathinfo, "/")) {
				pathinfo = StringUtils.substring(pathinfo, 1);
			}
			pathinfo = StringUtils.replace(pathinfo, "/", ".");
			return pathinfo;
		}
		
		/**
		 * 获取方法的唯一标识key
		 */
		public String getActionMethodKey(HttpServletRequest  request, String method) {
			if(StringUtils.isEmpty(method)){
				throw new TKException("method motho must not be null");
			}
			String requestKey = getActionUrlKey(request) + "." + method;
			return requestKey;
		}

}
